#ifndef _MEMORY_POOL_
#define _MEMORY_POOL_


#define BLOCK_SIZE 1024*4     //表明为4K
#define SIZE_OF_LARGE  1024*2   //大块内存的定义
#define PTR_ALIGN_SIZE 16
#define FAILED_TIMES 5
// using u_char = unsigned char;
typedef unsigned char u_char;

typedef struct small_mem{
    u_char *last;   //该块的当前指向
    u_char *end;    // 结束块
    int failed_num; // 分配失败次数
    int refer_count;      // 引用计数
    struct small_mem*next;  //下一块
    //int free_space;  //还能继续分配的空间  ----这个字段很鸡肋
}small_node;

typedef struct large_mem{
    void * alloc;   //当前块指向
    struct large_mem * next;    //指向下一块
}large_node;

typedef struct mem_node{
    struct small_mem head;   //头，这里就不用指针了
    struct small_mem * cur; //每次申请从cur开始判断
    struct large_mem *large;   //大块内存
} node;

class memory_pool{
private:
    node * pool;
public:
    memory_pool(){
        this->pool=nullptr;
    }
    void init();    //初始化root
    void * alloc_mem(int size); //申请内存的接口
    void reset_pool();  //重置pool
    ~memory_pool();     //释放全部申请的内存
private:
    void * alloc_small_mem(int size);   //申请小块内存
    void * alloc_large_mem(int size);   //申请大块内存
    void * alloc_new_small_mem(int size);
    void * align_ptr(void *ptr);


};



#endif